package com.hyzh.latte.sandtable.controller;

import com.hyzh.latte.sandtable.pojo.PointData;
import com.hyzh.latte.sandtable.pojo.QueryRequest.GeoQuery.FindShortestRoad;
import com.hyzh.latte.sandtable.pojo.Result;
import com.hyzh.latte.sandtable.pojo.Vector_Point_2D;
import com.hyzh.latte.sandtable.service.GeoQueryService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/geo_query")
@Slf4j
@AllArgsConstructor
public class GeoQueryController {
   private final GeoQueryService geoQueryService;

    @PostMapping("/find_shortest_road")
    public Result findShortestRoad(@RequestBody FindShortestRoad queryRequest) {
        try {
            List<Vector_Point_2D> resultPoints = geoQueryService.findShortestRoad(queryRequest.getStartPoint(), queryRequest.getEndPoint(), queryRequest.getArea());
            return Result.success(resultPoints);
        } catch (Exception e) {
            log.error("eoro", e);
            return Result.error("查询失败");
        }
    }

    @PostMapping("/point_fit_to_roads")
    public Result pointsFitToRoads(@RequestBody ArrayList<PointData> pointDataList) {
        try {
            List<PointData> resultPoints = geoQueryService.pointFitToRoads(pointDataList, "jiangan");
            return Result.success(resultPoints);
        } catch (Exception e) {
            return Result.error("查询失败");
        }
    }
}

